import flask
import werkzeug
import os
import execute
import requests
import pickle
from tf2st.p3.p3_ini_te.ty1 import get_config
from flask import request, jsonify

import numpy as np
from PIL import Image

gConfig = {}
gConfig = get_config(config_file='config.ini')

app = flask.Flask('imgClassifierWeb')


def CNN_predict():
    file = gConfig['dataset_path'] + 'batches.meta'

    patch_bin_file = open(file, 'rb')
    label_names_dict = pickle.load(patch_bin_file)['label_names']

    global secure_filename

    img = Image.open(os.path.join(app.root_path, secure_filename))

    r, g, b = img.split()

    r_arr = np.array(r)
    g_arr = np.array(g)
    b_arr = np.array(b)

    img=np.concatenate((r_arr,g_arr,b_arr))
    image=img.reshape([1,32,32,3])/255

    predicted_class=execute.predict(image)
